package com.dfbz.bigdata.modules.system.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther:东方标准
 * @Date:2022/9/27-09-27-20:45
 * @Decsription:com.dfbz.bigdata.modules.system.config
 * @Version:1.0
 */
@Configuration
public class CommonConfig extends HandlerInterceptorAdapter {
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")  // 拦截所有的请求
//                .allowedOrigins("*")  // 可跨域的域名，可以为 *
//                .allowCredentials(true)
//                .allowedMethods("*")   // 允许跨域的方法，可以单独配置
//                .allowedHeaders("*");  // 允许跨域的请求头，可以单独配置
//    }

        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            response.setHeader("Access-Control-Max-Age", "3600");
            response.setHeader("Access-Control-Allow-Headers", "*");
            response.setHeader("Access-Control-Allow-Credentials", "true");
            return true;
        }






}
